Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Sobolev smoothing method to the discrete adjoint gradient calculation. #1446

Merged

Conversation

thomasdick
Copy link
Contributor

@thomasdick thomasdick commented Nov 19, 2021

Proposed Changes

The proposed solver is a treatment of the discrete adjoint sensitivities based on the idea of Sobolev gradient smoothing.

Sobolev smoothing of gradients computes a reinterpretation of the gradient in a different Hilbert space, see this short overview.
This is done by solving an elliptic PDE with the sensitivities, i.e., ( e1 Id - e2 Laplace) delta_x = - dF / dx, with different weights e1, e2. Inserting the sensitivities from the discrete adjoint solver for (dF / dx) leads to the gradient in a Sobolev space.
The method can be extended to incorporate the parameterization of the mesh cells x=M(p) with design values p, see here. Using the projected gradient w.r.t. the design values the systems takes the form
(dM/dp)^T (e1 Id - e2 Laplace) (dM/dp) = - dF/dp.

Such treatment can help prevent noise in the derivative computation and leads to smoother design updates. Especially, when working in a One-Shot optimization context.
Here the optimization is done with inexact function values and gradients, i.e., the flow and adjoint solvers are only partially converged between design updates. For this setting simple gradient descent with too large update steps will not work, since a few flow iterations are not enough to recover a solution from the restart file from the last optimization step.
See the graphic below for drag minimization of a NACA 0012 airfoil with constant lift, where the Sobolev solver for the gradient leads to smoother deformations and better optimization.
pullrequest1

Application is done as a post-processing step in the SU2_DOT_AD executable.
The new solver constructs the necessary operator and solves it using the features of the finite element implementation in SU2. For this, it uses the same elements as the FEA solver but extends the definitions of the Gauss quadrature to be second order.
It can operate in two different modes:

  1. The smoothing can be applied to the mesh sensitivities, either in the complete mesh or only design boundaries. See the picture below for an example of this.
    PicforSU2

  2. It also includes the possibility to take the mesh parameterization into account, compute the derivatives (dM/dp), and smooth the sensitivities w.r.t. the design parameters. This is done by the same AD logic used in SU2_DOT.cpp::SetProjection_AD. The routines are extended, such that AD can compute arbitrary matrix-vector products with the Jacobian of the parameterization and apply the smoothing operator to the gradient.

This is a continuation of draft #1439 with a new rebased branch. It has a cleaner commit history and not so much legacy from previous versions.

The regression tests for this pull request need the files for the accompanying pull request su2code/TestCases/pull/88.

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with the '-Wall -Wextra -Wno-unused-parameter -Wno-empty-body' compiler flags, or simply --warnlevel=2 when using meson).
  • My contribution is commented and consistent with SU2 style.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp) , if necessary.

…nt treatement.

 - Solver works on mesh and design parameter level.
 - Can smooth the discrete adjoint gradient.
 - Support for printing the combined system matrix (Laplace-Beltrami operator).
 - Squashed old commits into new branch based on version 7.2.1 develop.
@pr-triage pr-triage bot added the PR: draft label Nov 19, 2021
@thomasdick thomasdick changed the title Feature sobolev smoothing solver [WIP] Add a Sobolev smoothing method to the discrete adjoint gradient calculation. Nov 19, 2021
Removed config option SENS_SMOOTHING, since it is not used and reworked testcase configs.
CGradientSmoothingSolver now uses the output precision from config OUTPUT_PRECISION.
 - Added the necessary solver, numerics, and variable classes there.
 - The method is called as an alternative parallel to SetProject_AD.
…dient smoothing to SU2_DOT.

 - Changed regressions tests for the Sobolev smoothing solver.
@thomasdick
Copy link
Contributor Author

Hi Pedro,
Yes, I misunderstood you last week. I have time today and will move the files back to the other solvers and numerics classes. About the meson build system, I still need to include them in the meson.build file for SU2_DOT and not SU2_CFD since they are needed there.

…THING map.

Cleaned up the switch statemnet for choosing a linear solver in CSysSolve.
Extended documentation in the smoothing solver TestCases.
…now build using the static su2_cfd libraries.
Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice feature.
This has quite a few changes so I'll have to review it in chunks.
First batch of comments below.

Common/include/CConfig.hpp Outdated Show resolved Hide resolved
Common/include/CConfig.hpp Outdated Show resolved Hide resolved
Common/include/CConfig.hpp Outdated Show resolved Hide resolved
Common/include/CConfig.hpp Outdated Show resolved Hide resolved
Common/include/CConfig.hpp Outdated Show resolved Hide resolved
Common/include/geometry/elements/CElement.hpp Outdated Show resolved Hide resolved
Common/include/geometry/elements/CElement.hpp Outdated Show resolved Hide resolved
Common/include/option_structure.hpp Outdated Show resolved Hide resolved
Common/include/CConfig.hpp Outdated Show resolved Hide resolved
Common/include/CConfig.hpp Outdated Show resolved Hide resolved
@thomasdick
Copy link
Contributor Author

Thanks for the comments 👍
I will implement the suggestions in the next commit.

Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second chunk, the new solver is neatly organized 👍

Common/src/CConfig.cpp Outdated Show resolved Hide resolved
Common/src/geometry/elements/CTETRA4.cpp Outdated Show resolved Hide resolved
Common/src/geometry/elements/CTETRA4.cpp Outdated Show resolved Hide resolved
Common/src/geometry/elements/CTETRA4.cpp Outdated Show resolved Hide resolved
SU2_CFD/include/numerics/CGradSmoothing.hpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/variables/CSobolevSmoothingVariable.cpp Outdated Show resolved Hide resolved
Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok got to the bottom :)

SU2_DOT/include/SU2_DOT.hpp Outdated Show resolved Hide resolved
SU2_DOT/src/SU2_DOT.cpp Outdated Show resolved Hide resolved
SU2_DOT/src/SU2_DOT.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
TestCases/grad_smooth/naca0012/inv_NACA0012_gradsmooth.cfg Outdated Show resolved Hide resolved
SU2_DOT/src/SU2_DOT.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
TestCases/grad_smooth/naca0012/inv_NACA0012_gradsmooth.cfg Outdated Show resolved Hide resolved
TestCases/grad_smooth/naca0012/inv_NACA0012_gradsmooth.cfg Outdated Show resolved Hide resolved
@thomasdick
Copy link
Contributor Author

Hi Pedro,
Thank you for viewing the code and all the suggestions!
I started changing the solver accordingly and will commit the changes soon.

Create a common template CFEASolverBase for solvers using the internal finite elements.
 - Adding a common CFeaSolverBase class for finite elements solvers.
 - making functions private and variables constant in CGradientSmoothingSolver.
 - reworked the storage of boundary vertices in CSobolevSmoothingVariable.
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
@thomasdick thomasdick force-pushed the feature_Sobolev_smoothing_solver branch from 45422ce to 608cfb2 Compare January 13, 2022 20:01
Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patience, I think we are down to final checks.

Common/src/geometry/elements/CLINE.cpp Outdated Show resolved Hide resolved
Common/src/grid_movement/CVolumetricMovement.cpp Outdated Show resolved Hide resolved
SU2_CFD/include/numerics/CGradSmoothing.hpp Outdated Show resolved Hide resolved
SU2_CFD/include/numerics/CGradSmoothing.hpp Outdated Show resolved Hide resolved
SU2_CFD/include/numerics/CGradSmoothing.hpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
TestCases/grad_smooth/naca0012/inv_NACA0012_gradsmooth.cfg Outdated Show resolved Hide resolved
Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok after this last batch LGTM, good simplification in SU2_DOT 👍
Have you tried a multizone case, even if it's just the NACA0012 duplicated?

SU2_DOT/src/SU2_DOT.cpp Outdated Show resolved Hide resolved
SU2_DOT/src/SU2_DOT.cpp Outdated Show resolved Hide resolved
SU2_DOT/src/SU2_DOT.cpp Outdated Show resolved Hide resolved
TestCases/grad_smooth/naca0012/inv_NACA0012_gradsmooth.cfg Outdated Show resolved Hide resolved
TestCases/grad_smooth/naca0012/inv_NACA0012_gradsmooth.cfg Outdated Show resolved Hide resolved
SU2_CFD/include/solvers/CGradientSmoothingSolver.hpp Outdated Show resolved Hide resolved
SU2_CFD/include/solvers/CGradientSmoothingSolver.hpp Outdated Show resolved Hide resolved
SU2_CFD/include/solvers/CGradientSmoothingSolver.hpp Outdated Show resolved Hide resolved
SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp Outdated Show resolved Hide resolved
@thomasdick
Copy link
Contributor Author

Thanks for reviewing all of the code Pedro 👍
I hope this is the last batch of major changes.

Regarding your question about multizone:
I created a case with duplicated NACA0012 airfoil as suggested and I get two output files. One per zone, each containing the result you would expect for a singlezone.

Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍 LGTM

@TobiKattmann
Copy link
Contributor

TobiKattmann commented Jan 19, 2022

@thomasdick @pcarruscag Please leave this open until Saturday 6pm German time. I want to take a look at this as well :) Dont expect any major requested changes from me but I hope to find a few spots to nag about :D

Edit: Forget this 👆 , I will scroll over this in silence at some point. But already thanks @thomasdick for the effort and the contribution :)

@thomasdick
Copy link
Contributor Author

Added the reference files for file diff and merged with the latest development branch.

@pcarruscag pcarruscag merged commit 2908bfc into su2code:develop Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants